﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Linq;
namespace Itop.YHPC
{
    public partial class DataViewImages : System.Web.UI.Page
    {
        string strImage = "{'images':[";
        string[] strExten = { "*.jpg", "*.bmp", "*.gif", "*.png" };
        string strUserName;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string path = Server.MapPath("Upload/");
                Session["UserName"] = "zack";
                strUserName = Session["UserName"].ToString();

                string imageid = Request.QueryString["imageid"];
                string image1 = "image1" + imageid;
                string image2 = "image2" + imageid;
                string image3 = "image3" + imageid;
                string image4 = "image4" + imageid;
                if (!path.EndsWith(@"\"))
                    path += @"\";
                bool image1flag = false, image2flag = false, image3flag = false, image4flag = false;
                string strimage1 = "", strimage2 = "", strimage3 = "", strimage4 = "";
                DirectoryInfo di = new DirectoryInfo(path);
                if (!string.IsNullOrEmpty(imageid))
                {
                    foreach (string strExtension in strExten)
                    {
                        FileInfo[] fi = di.GetFiles(strExtension);

                        foreach (FileInfo f in fi)
                        {
                            if (f.Name.Contains(image1 + "_"))
                            {
                                image1flag = true;
                                strimage1 = "{'name':'" + f.Name + "','url':'../Upload/" + f.Name + "','size':'" + f.Length + "','type':'排查阶段'},";
                            }

                            if (f.Name.Contains(image2 + "_"))
                            {
                                image2flag = true;
                                strimage2 = "{'name':'" + f.Name + "','url':'../Upload/" + f.Name + "','size':'" + f.Length + "','type':'预控阶段'},";
                            }
                            if (f.Name.Contains(image3 + "_"))
                            {
                                image3flag = true;
                                strimage3 = "{'name':'" + f.Name + "','url':'../Upload/" + f.Name + "','size':'" + f.Length + "','type':'治理阶段'},";
                            }
                            if (f.Name.Contains(image4 + "_"))
                            {
                                image4flag = true;
                                strimage4 = "{'name':'" + f.Name + "','url':'../Upload/" + f.Name + "','size':'" + f.Length + "','type':'验收阶段'},";
                            }

                        }
                    }
                    if (!image1flag)
                    {
                        strimage1 = "{'name':'image1null ','url':'../Upload/image1null.jpg ','size':'0','type':'排查阶段'},";
                    }
                    if (!image2flag)
                    {
                        strimage2 = "{'name':'image2null ','url':'../Upload/image2null.jpg ','size':'0','type':'预控阶段'},";
                    }
                    if (!image3flag)
                    {
                        strimage3 = "{'name':'image3null ','url':'../Upload/image3null.jpg ','size':'0','type':'治理阶段'},";
                    }
                    if (!image4flag)
                    {
                        strimage4 = "{'name':'image4null ','url':'../Upload/image4null.jpg ','size':'0','type':'验收阶段'},";
                    }
                    strImage += strimage1 + strimage2 + strimage3 + strimage4;
                }
                else
                {
                    foreach (string strExtension in strExten)
                    {
                        FileInfo[] fi = di.GetFiles(strExtension);

                        foreach (FileInfo f in fi)
                        {
                            if (f.Name.StartsWith(strUserName + "_"))
                            {
                                strImage += "{'name':'" + f.Name + "','url':'../Upload/" + f.Name + "','size':'" + f.Length + "','type':'阶段'},";
                            }
                        }
                    }
                }




                strImage = strImage.Substring(0, (strImage.Length - 1));
                strImage += "]}";

                Response.Write(strImage);
                Response.End();
            }
        }
    }
}
